﻿using DiffisionWithDecomposition;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DiffusionOneShot
{
    class Program
    {
        static void Main(string[] args)
        {
            MainLoop();
        }

        private static void ReadComplete(string returnValue)
        {
            
        }

        public static void MainLoop()
        {
            
            SimParameters.T_s = 400 * 1000 * 1000; // msec
            SimParameters.SimDuration = 401 * 1000 * 1000;
            SimParameters.NumberOfMolecules = 1000;
            SimParameters.MoleculeHalfLife = 4 * 1000 * 1000;
            SimParameters.DecompositionEnabled = true;
            SimParameters.StepSize = 0.000001;
            SimParameters.TimeTick = 1000;
            SimParameters.ReportInterval = 10000000;
            SimParameters.MaxDistanceFromCellCenter = 1000000;
            SimParameters.XCoordinateOfCellPosition = 14;

            var numberOfRepeats = 1000;

            var _streamWiter = new StreamWriter(String.Format("Logs\\OneShot D={0}, N={1}, Dec={2}, HL={3}.txt, T_s={4}, Durat = {5}.txt, Repe={6}, dT={7}.txt", SimParameters.XCoordinateOfCellPosition,
                SimParameters.NumberOfMolecules, SimParameters.DecompositionEnabled, SimParameters.MoleculeHalfLife, SimParameters.T_s, SimParameters.SimDuration, numberOfRepeats, SimParameters.StepSize), false);


            for (int i = 0; i < numberOfRepeats; i++)
            {
                Simulation.Instance.NewSimulationInstance();

                var communication = new Communication();
                communication._streamWiter = _streamWiter;
                communication.SendOneBit(SimParameters.NumberOfMolecules, SimParameters.T_s);

                while (Simulation.Instance.EndCondition == false)
                {
                    Simulation.Instance.DequeueEvent();
                }

                _streamWiter.Flush();
            }
            
            _streamWiter.Close();

            //WriteStuff(_streamWiter, communication);
        }
    }
}
